package com.pgybook.db.entity.mapper;

import org.springframework.stereotype.Repository;
import com.pgybook.db.entity.domain.BookCategory;
import com.pgybook.db.entity.domain.BookCategoryEx;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Repository
public interface BookCategoryMapper {
    int countByExample(BookCategoryEx example);

    int deleteByExample(BookCategoryEx example);

    @Delete({
            "delete from bookcategory",
            "where CATEGORYID = #{categoryid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer categoryid);

    @Insert({
            "insert into bookcategory (NAME, PARENT, ",
            "LEVEL, DESCRIPTION, ",
            "CRTTIME, CRTSTAFF, ",
            "UPDTIME, UPDSTAFF)",
            "values (#{name,jdbcType=VARCHAR}, #{parent,jdbcType=INTEGER}, ",
            "#{level,jdbcType=INTEGER}, #{description,jdbcType=VARCHAR}, ",
            "#{crttime,jdbcType=TIMESTAMP}, #{crtstaff,jdbcType=INTEGER}, ",
            "#{updtime,jdbcType=TIMESTAMP}, #{updstaff,jdbcType=INTEGER})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "categoryid", before = false, resultType = Integer.class)
    int insert(BookCategory record);

    int insertSelective(BookCategory record);

    List<BookCategory> selectByExample(BookCategoryEx example);

    @Select({
            "select",
            "CATEGORYID, NAME, PARENT, LEVEL, DESCRIPTION, CRTTIME, CRTSTAFF, UPDTIME, UPDSTAFF",
            "from bookcategory",
            "where CATEGORYID = #{categoryid,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    BookCategory selectByPrimaryKey(Integer categoryid);

    int updateByExampleSelective(@Param("record") BookCategory record, @Param("example") BookCategoryEx example);

    int updateByExample(@Param("record") BookCategory record, @Param("example") BookCategoryEx example);

    int updateByPrimaryKeySelective(BookCategory record);

    @Update({
            "update bookcategory",
            "set NAME = #{name,jdbcType=VARCHAR},",
            "PARENT = #{parent,jdbcType=INTEGER},",
            "LEVEL = #{level,jdbcType=INTEGER},",
            "DESCRIPTION = #{description,jdbcType=VARCHAR},",
            "CRTTIME = #{crttime,jdbcType=TIMESTAMP},",
            "CRTSTAFF = #{crtstaff,jdbcType=INTEGER},",
            "UPDTIME = #{updtime,jdbcType=TIMESTAMP},",
            "UPDSTAFF = #{updstaff,jdbcType=INTEGER}",
            "where CATEGORYID = #{categoryid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(BookCategory record);
}
